package org.example.bean.service;

import org.example.bean.model.LoginParam;
import org.example.bean.model.LoginTypeEnum;
import org.example.bean.model.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class PhoneLoginService extends AbstractLoginService {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    protected PhoneLoginService(LoginCommonStragegyRegistry loginCommonStragegyRegistry) {
        super(loginCommonStragegyRegistry);
    }

    @Override
    protected void initRegistry() {
        super.loginCommonStragegyRegistry.registry(LoginTypeEnum.PHONETYPE, this.getClass());
    }

    @Override
    public Result checkParam(LoginParam loginParam) {
        if (ObjectUtils.isEmpty(loginParam.getPhone())) {
            return Result.error("手机号不能为空！");
        }
        if (ObjectUtils.isEmpty(loginParam.getSmsCode())) {
            return Result.error("短信验证码不能为空！");
        }
        return Result.suc("手机号登录参数校验通过！");
    }

    @Override
    public Result login(LoginParam loginParam) {
        log.info("手机号登录开始...");
        if (loginParam.getPhone().equals("13800138000")
                && loginParam.getSmsCode().equals("123456")) {
            return Result.suc("手机号登录成功！");
        }
        return Result.error("手机号登录失败！");
    }

}
